package com.schoolET.controller.wechat;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.schoolET.entity.vo.PurchaseGoodsVO;
import com.schoolET.result.Result;
import com.schoolET.service.wechat.TradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author: lin
 * @className: TradeController
 * @createTime: 2024-06-12  20:57
 * @description: 交易接口
 */
@Api(tags = "商品交易接口")
@RestController
@RequestMapping("/schoolET/wx")
public class TradeController {

    @Resource
    private TradeService tradeService;


    @ApiOperationSupport(author = "lin")
    @ApiOperation(value = "购买商品")
    @PostMapping("/buyGoods")
    @SaCheckLogin
    public Result queryGoods(@Valid @RequestBody PurchaseGoodsVO purchaseGoodsVO) {
        String loginIdAsString = StpUtil.getLoginIdAsString();
        tradeService.purchaseOfGoods(purchaseGoodsVO,loginIdAsString);
        return Result.success().msg("购买成功");
    }

    @ApiOperationSupport(author = "lin")
    @ApiOperation(value = "确认收货")
    @GetMapping("/orderOver/{id}")
    @SaCheckLogin
    public Result orderOver(@PathVariable Integer id) {
        String loginIdAsString = StpUtil.getLoginIdAsString();
        tradeService.orderOver(id, loginIdAsString);
        return Result.success().msg("确认成功");
    }

    @ApiOperationSupport(author = "lin")
    @ApiOperation(value = "终止交易")
    @GetMapping("/orderEnd/{id}")
    @SaCheckLogin
    public Result orderEnd(@PathVariable Integer id) {
        String loginIdAsString = StpUtil.getLoginIdAsString();
        tradeService.orderEnd(id, loginIdAsString);
        return Result.success().msg("确认成功");
    }

}
